//======================
//连接mysql
//======================

//导入sequelize, 并且解构Sequelize
let {
    Sequelize
} = require('sequelize');

let sql = config.mySqlOptions;
//连接mysql数据库
let sequelize = new Sequelize(sql.dbname, sql.user, sql.password, {
    //数据库地址
    host: sql.host,
    //数据库类型
    dialect: 'mysql',
    //时区
    timezone: '+08:00',

    //字段命名 以 _ 分隔
    define: {
        underscored: true
    }
})
// async function tryConnent() {
//     try {
//         await sequelize.authenticate();
//         console.log('Connection has been established successfully.');
//     } catch (error) {
//         console.error('Unable to connect to the database:', error);
//     }
// }
// tryConnent();
//导出实例，以便后续创建模型需要使用该连接实例
module.exports = sequelize;